package com.example.horizonserver.controller;

import com.example.horizonserver.common.result.PageResult;
import com.example.horizonserver.common.result.Result;
import com.example.horizonserver.pojo.DTO.*;
import com.example.horizonserver.pojo.VO.DispatchSubmitVO;
import com.example.horizonserver.service.DispatchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/dispatch")
public class DispatchController {

    @Autowired
    private DispatchService dispatchService;

    /**
     * 用户发起用车申请
     * @param dispatchSubmitDTO
     * @return
     */
    @PostMapping("/submit")
    public Result<DispatchSubmitVO> submit(@RequestBody DispatchSubmitDTO dispatchSubmitDTO)
    {
        DispatchSubmitVO dispatchSubmitVO = dispatchService.submitDispatch(dispatchSubmitDTO);
        return Result.success(dispatchSubmitVO);
    }

    /**
     * 管理员批准用车
     *
     * @return
     */
    @PutMapping("/confirm")
    public Result<String> confirm(@RequestBody DispatchConfirmDTO dispatchConfirmDTO) {
        dispatchService.confirm(dispatchConfirmDTO);
        return Result.success();
    }

    /**
     * 管理员驳回用车
     *
     * @return
     */
    @PutMapping("/rejection")
    public Result<String> rejection(@RequestBody DispatchRejectionDTO dispatchRejectionDTO){
        dispatchService.rejection(dispatchRejectionDTO);
        return Result.success();
    }

    /**
     * 完成使用 归还车辆
     *
     * @return
     */
    @PutMapping("/complete")
    public Result<String> complete(@RequestBody DispatchCompleteDTO dispatchCompleteDTO) {
        dispatchService.complete(dispatchCompleteDTO);
        return Result.success();
    }

    /**
     * 条件分页查询调度记录
     *
     * @return
     */


    @GetMapping("/page")
    public Result<PageResult> page(DispatchPageQueryDTO dispatchPageQueryDTO)
    {
        PageResult pageResult = dispatchService.pageQuery(dispatchPageQueryDTO);
        return Result.success(pageResult);
    }



}
